import React from "react";
import { Redirect, Route } from "react-router-dom";
import store from "../redux";

// 接收一个组件，返回一个组件
export default ({ component: Cmp, ...rest }) => {
    return (
        <Route
            {...rest}
            render={(props) => {
                // 如果登录了
                if (store.getState().token) {
                    return <Cmp {...props} />;
                }
                return <Redirect to="/login" />;
            }}
        />
    );
};
